from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field

from app.models.enums import StatusType


class BaseRole(BaseModel):
    id: int
    name: str
    desc: str = ""
    users: Optional[list] = []
    menus: Optional[list] = []
    apis: Optional[list] = []
    created_at: Optional[datetime]
    updated_at: Optional[datetime]


class RoleCreate(BaseModel):
    code: str = Field(..., description="编码")
    name: str = Field(..., description="名称")
    desc: Optional[str] = Field("", description="描述")
    status: Optional[int] = Field(StatusType.ENABLED, description="状态")
    permissions: Optional[list[int]] = Field([], description="权限列表")


class RoleUpdate(BaseModel):
    id: int = Field(..., description="ID")
    name: Optional[str] = Field(None, description="名称")
    desc: Optional[str] = Field(None, description="描述")
    status: Optional[int] = Field(None, description="状态")
    permissions: Optional[list[int]] = Field(None, description="权限列表")


class RoleUpdateMenusApis(BaseModel):
    id: int
    menu_ids: list[int] = []
    api_infos: list[dict] = []
